﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Xml.Linq;

namespace Dln.Handler
{
    /// <summary>
    /// 
    /// </summary>
    public class TextMessage:Message
    {
        /// <summary>
        /// 内容
        /// </summary>
        public string Content { get; set; }
        /// <summary>
        /// 消息ID
        /// </summary>
        public string MsgId { get; set; }
        /// <summary>
        /// 从xml数据加载文本消息
        /// </summary>
        /// <param name="xml"></param>
        public static TextMessage LoadFromXml(string xml)
        {
            TextMessage tm = null;
            if (!string.IsNullOrEmpty(xml))
            {
                XElement element = XElement.Parse(xml);
                if (element != null)
                {
                    tm = new TextMessage();
                    tm.FromUserName = element.Element(XMLNodeConfig.FROM_USERNAME).Value;
                    tm.ToUserName = element.Element(XMLNodeConfig.TO_USERNAME).Value;
                    tm.CreateTime = element.Element(XMLNodeConfig.CREATE_TIME).Value;
                    tm.Content = element.Element(XMLNodeConfig.CONTENT).Value;
                    tm.MsgId = element.Element(XMLNodeConfig.MSG_ID).Value;
                }
            }

            return tm;
        }
      
    }
}
